﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace RbmlVisualizer
{
    /// <summary>
    /// Interaction logic for MenuBar.xaml
    /// </summary>
    public partial class MenuBar : UserControl
    {
        public MenuBar()
        {
            InitializeComponent();
        }

        private void closeButton_Click(object sender, RoutedEventArgs e)
        {
            Window currentWindow = GetTopParent();
            currentWindow.Close(); 
        }

        private void minimizeButton_Click(object sender, RoutedEventArgs e)
        {
            Window currentWindow = GetTopParent();
            currentWindow.WindowState = WindowState.Minimized; 
        }

        private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Window currentWindow = GetTopParent();
            currentWindow.DragMove();       
        }

        private Window GetTopParent()
        {
            DependencyObject dpParent = this.Parent;
            do
            {
                dpParent = LogicalTreeHelper.GetParent(dpParent);

            } while (dpParent.GetType().BaseType != typeof(Window));
            return dpParent as Window;
        }

        private void maximizeButton_Click(object sender, RoutedEventArgs e)
        {
            Window currentWindow = GetTopParent(); 
            if (currentWindow.WindowState == WindowState.Maximized)
            {
                currentWindow.WindowState = WindowState.Normal;
            }
            else
            {
                currentWindow.WindowState = WindowState.Maximized;
            }
        }

        private void UserControl_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            Window currentWindow = GetTopParent();
            if (currentWindow.WindowState == WindowState.Maximized)
            {
                currentWindow.WindowState = WindowState.Normal;
            }
            else
            {
                currentWindow.WindowState = WindowState.Maximized;
            }
        }

    }
}
